﻿using Admin2024.Application.Contracts.User.Dto;
using Admin2024.Domain.Entity.System;
using Admin2024.Domain.IDomainService.System.IUserService;
using Admin2024.Domain.ObjValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin2024.Application.Contracts.User
{
    public class UserStateService : IUserStateService
    {

        private readonly IUserStateManager _userStateManager;


        public UserStateService(IUserStateManager userStateManager)
        {
            _userStateManager = userStateManager;
        }
        //批量删除
        public async Task<DomainResult<IEnumerable<string>>> DeleteRangeAsync(IEnumerable<Guid> ids)
        {
            var list = await _userStateManager.DeleteRangeAsync(ids);
            return DomainResult<IEnumerable<string>>.Success(list.Data);
        }
        //硬删除用户
        public async Task<DomainResult<UserDeleteDto>> DeleteUserAsync(Guid id)
        {

            var user = await _userStateManager.DeleteUserAsync(id);

            if (!user.IsSuccess)
            {
                return DomainResult<UserDeleteDto>.Error(user.Message);
            }
            var userDeleteDto = new UserDeleteDto
            {
                Id = user.Data.Id
            };
            return DomainResult<UserDeleteDto>.Success(userDeleteDto);
        }

        public async Task<DomainResult<Guid>> DisableUserAsync(Guid id)
        {
            var user = await _userStateManager.DisableUserAsync(id);

            if (!user.IsSuccess)
            {
                return DomainResult<Guid>.Error(user.Message);
            }
 
            return DomainResult<Guid>.Success(user.Data.Id);
        }

        public async Task<DomainResult<Guid>> EnableUserAsync(Guid id)
        {
            var user = await _userStateManager.EnableUserAsync(id);

            if (!user.IsSuccess)
            {
                return DomainResult<Guid>.Error(user.Message);
            }

            return DomainResult<Guid>.Success(user.Data.Id);
        }
    }
}
